/**
 * author:Administrator
 * date:2013-5-21
 */
package com.roc.web.action.terminal;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;

/**
 * 
 * @author 陈锴
 * 
 * 终端申请
 * 
 * 2014-08-13
 *
 */
public class TerminalApplySearchCondition extends BaseSearchCondition {
	

	private String orgCode;
	private String status;
	private String merchantNo;
	private String merchantName;
	

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getOrderPartOfHQL()
	 */
	@Override
	protected String getOrderPartOfHQL() {
		// TODO Auto-generated method stub
		
		return " ORDER BY t.dt_create DESC ";
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getRowCountHQL()
	 */
	@Override
	protected String getRowCountHQL() {//,OrgBean o  t.orgCode = o.org_code
		StringBuffer sb=new StringBuffer();
		sb.append(" SELECT COUNT(*) ");
		sb.append(" FROM t_term_apply t ");
		sb.append(" INNER JOIN t_org o ");
		sb.append(" ON t.org_code = o.org_code ");
		sb.append(" WHERE 1=1 ");
		return sb.toString();
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getSearchHQL()
	 */
	@Override
	protected String getSearchHQL() {
		StringBuffer sb=new StringBuffer();
		sb.append(" SELECT t.merchant_no,t.merchant_name,o.org_name,t.term_applyed,NVL(t.term_installed,'0'),t.dt_create,t.operators,t.id,t.status ");
		sb.append(" FROM t_term_apply t ");
		sb.append(" INNER JOIN t_org o ");
		sb.append(" ON t.org_code = o.org_code ");
		sb.append(" WHERE 1=1 ");
		return sb.toString();
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getWhereHQLFieldBeanList()
	 */
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();

		
		if (Constance.isNotEmpty(orgCode)) {
			filedBeanList.add(new WhereHQLFieldBean("o.org_code", orgCode, "=", false));
		}

		if (Constance.isNotEmpty(merchantName)) {
			filedBeanList.add(new WhereHQLFieldBean("t.merchant_name", merchantName.trim(),
					"LIKE", false, "ALL"));
		}
		if (Constance.isNotEmpty(merchantNo)) {
			filedBeanList.add(new WhereHQLFieldBean("t.merchant_no", merchantNo, "=", false));
		}
		if(!status.equals("99")){
			if(status.equals("01")){  //待添加
				filedBeanList.add(new WhereHQLFieldBean("t.term_applyed <> t.term_installed"));
			}
			if(status.equals("02")){   //添加完成
				filedBeanList.add(new WhereHQLFieldBean("t.term_applyed = t.term_installed"));
			}
		}
		
		return filedBeanList;
	}


	public String getOrgCode() {
		return orgCode;
	}

	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getMerchantNo() {
		return merchantNo;
	}

	public void setMerchantNo(String merchantNo) {
		this.merchantNo = merchantNo;
	}

	public String getMerchantName() {
		return merchantName;
	}

	public void setMerchantName(String merchantName) {
		this.merchantName = merchantName;
	}

}
